package com.mirror.utils.base;

import java.util.List;

public class Page extends BasePage {

	/** 其他 */
	public static final int RESULT_NONE = -2;

	/** 失败 */
	public static final int RESULT_FAIL = -1;

	/** 成功，结果集为空 */
	public static final int RESULT_EMPTY = 0;

	/** 成功，结果集少于页大小 */
	public static final int RESULT_VACANT = 1;

	/** 成功，结果集等于页大小 */
	public static final int RESULT_FULL = 2;

	public static final int OPERATE_NONE = -1;

	public static final int OPERATE_REFESH = 0;

	public static final int OPERATE_MORE = 1;

	private int operateType;

	private int operateResult;

	public Page() {
	}

	public Page(int pageIndex, int pageSize) {
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
	}

	public Page(int pageIndex, int pageSize, int operateType, int operateResult) {
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.operateType = operateType;
		this.operateResult = operateResult;
	}

	public <T> void result(List<T> list) {
		if (list == null) {
			operateResult = RESULT_FAIL;
		} else if (list.size() == 0) {
			operateResult = RESULT_EMPTY;
		} else if (list.size() > 0 && list.size() < pageSize) {
			operateResult = RESULT_VACANT;
		} else if (list.size() == pageSize) {
			operateResult = RESULT_FULL;
		} else {
			operateResult = RESULT_NONE;
		}
	}

	public Page first(int operateType) {
		return new Page(1, pageSize, operateType, Page.RESULT_NONE);
	}

	public Page next(int operateType) {
		return new Page(pageIndex + 1, pageSize, operateType, Page.RESULT_NONE);
	}

	public Page max(int operateType) {
		return new Page(1, Integer.MAX_VALUE, operateType, Page.RESULT_NONE);
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getOperateType() {
		return operateType;
	}

	public void setOperateType(int operateType) {
		this.operateType = operateType;
	}

	public int getOperateResult() {
		return operateResult;
	}

	public void setOperateResult(int operateResult) {
		this.operateResult = operateResult;
	}

	@Override
	public String toString() {
		return "Page [pageIndex=" + pageIndex + ", pageSize=" + pageSize + ", operateType=" + operateType + ", operateResult=" + operateResult + "]";
	}

}
